{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-21T07:06:16.888787Z",
     "start_time": "2025-09-21T07:06:08.637816Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from time import sleep\n",
    "\n",
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "\n",
    "wd = webdriver.Chrome()\n",
    "wd.implicitly_wait(10)\n",
    "\n",
    "wd.get('https://www.byhy.net/cdn2/files/selenium/stock1.html')\n",
    "\n",
    "element = wd.find_element(By.ID, 'kw')\n",
    "element.clear()\n",
    "element.send_keys('通讯\\n')\n",
    "\n",
    "sleep(2)\n",
    "\n",
    "element = wd.find_element(By.ID, 'kw')\n",
    "element.clear()\n",
    "element.send_keys('科技\\n')"
   ],
   "id": "c83ea4185be2e0ea",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-21T08:13:34.763685Z",
     "start_time": "2025-09-21T08:13:26.104452Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 获取元素信息\n",
    "from time import sleep\n",
    "\n",
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "\n",
    "wd = webdriver.Chrome()\n",
    "wd.implicitly_wait(10)\n",
    "\n",
    "wd.get('https://www.byhy.net/cdn2/files/selenium/stock1.html')\n",
    "\n",
    "element = wd.find_element(By.ID, '1')\n",
    "print(element.tag_name)\n",
    "print(element.get_attribute('class'))\n",
    "print(element.get_attribute('innerHTML'))"
   ],
   "id": "7569fd74ccd9f113",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "div\n",
      "result-item\n",
      "\n",
      "          <p class=\"name\">包钢股份</p>\n",
      "          <p>代码：<span>600010</span></p>\n",
      "        \n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "f15f1ef0bd458a88"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
